﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SzCourt.Logic.BLL;

namespace SzCourt.WebSite.manager
{
    public partial class reg : System.Web.UI.Page
    {
        private string _Name = string.Empty;
        private string _Password = string.Empty;
        private string _Dept = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!AdminSession.SessionBox.CheckUserSession())
            {
                this.spMessage.InnerHtml = "您没有注册网站管理员的权限！";
                Response.Redirect("/manager/login.aspx");
            }
            else if (AdminSession.SessionBox.GetUserSession().UserName.Length == 0 || AdminSession.SessionBox.GetUserSession().UserName.ToLower() != "sysadmin")
            {
                this.spMessage.InnerHtml = "您没有注册网站管理员的权限！";
            }
            else
            {
                this.tblReg.Visible = true;
            }
            if (!this.IsPostBack)
            {
                getParam();
                if (this._Name.Length > 0 && this._Password.Length > 0 && this._Dept.Length > 0)
                {
                    createrInfo();
                }
            }
        }

        //获取参数值
        private void getParam()
        {
            this._Name = string.IsNullOrEmpty(Request.Form["txtName"]) ? "" : Request.Form["txtName"];
            this._Password = string.IsNullOrEmpty(Request.Form["txtPassword"]) ? "" : Request.Form["txtPassword"];
            this._Dept = string.IsNullOrEmpty(Request.Form["hdnDept"]) ? "" : Request.Form["hdnDept"];
        }

        private void createrInfo()
        {
            AdminUser bll = new AdminUser();
            bool result = (bool)bll.CreateUser(this._Name, this._Password, this._Dept);

            if (result)
            {
                this.spMessage.InnerHtml = "用户注册成功！";
            }
            else
            {
                this.spMessage.InnerHtml = "用户注册失败！";
            }
        }

    }
}